import { fileURLToPath, URL } from "node:url";

import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import vueSetupExtend from 'vite-plugin-vue-setup-extend'
import postCssPxToRem from "postcss-pxtorem"
import Components from 'unplugin-vue-components/vite';
import { VantResolver } from 'unplugin-vue-components/resolvers';
// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue(), vueSetupExtend(), Components({
    resolvers: [VantResolver()],
  })],
  css: {
    postcss: {
      plugins: [
        postCssPxToRem({
          rootValue: 40, // 根据设计图 计算1rem单位 设计图十分之一
          propList: ['*'], // 需要转换的属性，这里选择全部都进行转换 单位使用PX默认不转换rem
        })
      ]
    }
  },
  resolve: {
    alias: {
      "@": fileURLToPath(new URL("./src", import.meta.url)),
      "@a": fileURLToPath(new URL("./src/api", import.meta.url)),
      "@c": fileURLToPath(new URL("./src/components", import.meta.url)),
      "@s": fileURLToPath(new URL("./src/stores", import.meta.url)),
      "@u": fileURLToPath(new URL("./src/utils", import.meta.url)),
      "@v": fileURLToPath(new URL("./src/views", import.meta.url)),
    },
  },
  server: {
    host: "0.0.0.0",
    port: 3000,
    open: true,
    proxy: {
      '/conner': {
        target: 'https://api.it120.cc',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/conner/, '/conner'),
      },
    }
  }
});
